package com.jarvis.dubbo.filter;

import com.jarvis.dubbo.utils.UserHolder;
import org.apache.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

/**
 * TODO XXX
 *
 * @author liangjw
 * created in 2020/9/18
 */
public class TokenConsumerFilter implements Filter {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String token = String.valueOf(new Random().nextDouble());
        System.out.println(String.format("consumer send a token(%s)", token));
        RpcContext.getContext().setAttachment("tokenString", token);
        return invoker.invoke(invocation);
    }
}
